/*
	Copyright (C) 2008 Demiurg-HG
	
	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
// ui_background.cpp - 

#include "ui_local.h"

#error file should be excluded from project

//
//	EUIBackground::EUIBackground
//
EUIBackground::EUIBackground(EUserInterface *ui)
{
	this->ui=	ui;
	shell	=	ui->shell;
	core	=	ui->core;
	rs		=	ui->rs;
	sys		=	ui->sys;
	
	ui_background	=	shell->RegisterVar("ui_background", "0", 0);
}


//
//	EUIBackground::~EUIBackground
//
EUIBackground::~EUIBackground(void)
{
}


//
//	EUIBackground::DrawBlackStripes
//
void EUIBackground::DrawBlackStripes(void)
{
	uint w, h;
	rs->GetScreenRect(w, h);
	float fh    = (float)h;
	float fw    = (float)w;
	float w16_9 = fw;
	float h16_9 = fw / 16.0f * 9.0f;
	float stripe_height = (fh - h16_9) / 2.0f;
	
	
	rs->DrawStretchImage(0, 0,					w16_9, stripe_height, "*black");
	rs->DrawStretchImage(0, fh - stripe_height, w16_9, stripe_height, "*black");
}



//
//	EUIBackground::DrawBackground
//
void EUIBackground::DrawBackground(void)
{
	int id = ui_background->Int();
	
	if (id==0) GFXFire();
	if (id==1) GFXWaves();
	
//	DrawBlackStripes();
}


void EUIBackground::GFXWaves(void)
{
	uint w, h;
	rs->GetScreenRect(w, h);
	float fh    = (float)h;
	float fw    = (float)w;
	float w16_9 = fw;
	float h16_9 = fw / 16.0f * 9.0f;
	float stripe_height = (fh - h16_9) / 2.0f / h16_9;

	//rs->SetCustom2DViewMode(EVec2(0, -stripe_height), EVec2(1, 1+stripe_height));
	rs->SetCustom2DViewMode(EVec2(0, 0), EVec2(1, 1));

	rs->DrawStretchImage(0, 0, 1, 1, "*black");

	quad_s q;
	float offset_x, offset_y, scale;
	float t = sys->Milliseconds() / 3000.0f;

	q.color = EVec4(1,1,1,1);
	q.p0	= EVec2(0,0);
	q.p1	= EVec2(1,1);

	offset_x	=	-t * 0.1f;
	q.p0	= EVec2(0,0);
	q.p1	= EVec2(1,1);
	q.uv0	= EVec2(0.0f + offset_x, 0.0f);
	q.uv1	= EVec2(0.5f + offset_x, 1.0f);
	rs->DrawQuadList(1, &q, "ui/spectrum.tga");


	scale		= 0.2f * sin( 2.00f * t);
	offset_x	=		-t * 0.9f;
	offset_y    = 0.1f * sin(0.1f * t);
	q.p0	= EVec2(0,0 - scale);
	q.p1	= EVec2(1,1 + scale);
	q.uv0	= EVec2(0.0f + offset_x, 0.0f + offset_y);
	q.uv1	= EVec2(0.5f + offset_x, 1.0f + offset_y);
	rs->DrawQuadList(1, &q, "ui/wave.tga");

	scale		= 0.4f * sin( 3.00f * t);
	offset_x	=		t * 1.3f;
	offset_y    = 0.1f * sin(0.13f * t);
	q.p0	= EVec2(0,0 - scale);
	q.p1	= EVec2(1,1 + scale);
	q.uv0	= EVec2(0.0f + offset_x, 0.0f + offset_y);
	q.uv1	= EVec2(0.2f + offset_x, 1.0f + offset_y);
	rs->DrawQuadList(1, &q, "ui/wave.tga");

	scale		= 0.3f * sin( 2.50f * t);
	offset_x	=		t * 0.5f;
	offset_y    = 0.1f * sin(0.14f * t);
	q.p0	= EVec2(0,0 - scale);
	q.p1	= EVec2(1,1 + scale);
	q.uv0	= EVec2(0.0f + offset_x, 0.0f + offset_y);
	q.uv1	= EVec2(0.3f + offset_x, 1.0f + offset_y);
	rs->DrawQuadList(1, &q, "ui/wave.tga");

	scale		= 0.3f * sin( 3.50f * t);
	offset_x	=		-t * 0.7f;
	offset_y    = 0.1f * sin(0.15f * t);
	q.p0	= EVec2(0,0 - scale);
	q.p1	= EVec2(1,1 + scale);
	q.uv0	= EVec2(0.0f + offset_x, 0.0f + offset_y);
	q.uv1	= EVec2(0.7f + offset_x, 1.0f + offset_y);
	rs->DrawQuadList(1, &q, "ui/wave.tga");


	rs->Set2DViewMode();
}



void EUIBackground::GFXFire(void)
{
	uint w, h;
	rs->GetScreenRect(w, h);
	float fh    = (float)h;
	float fw    = (float)w;
	float w16_9 = fw;
	float h16_9 = fw / 16.0f * 9.0f;
	float stripe_height = (fh - h16_9) / 2.0f / h16_9;

	//rs->SetCustom2DViewMode(EVec2(0, -stripe_height), EVec2(1, 1+stripe_height));
	rs->SetCustom2DViewMode(EVec2(0, 0), EVec2(1, 1));

	rs->DrawStretchImage(0, 0, 1, 1, "*black");

	rs->SetCustom2DViewMode(EVec2(0, 0), EVec2(1, 1));

	quad_s q;
	float offset   = sys->Milliseconds() / 4000.0f;
	float offset_x = sin(sys->Milliseconds() / 4000.0f);

	q.color = EVec4(1,1,1,1);
	q.p0	= EVec2(0,0);
	q.p1	= EVec2(1,1);
	q.uv0	= EVec2(0.0f + offset_x, 0.0f + offset);
	q.uv1	= EVec2(0.7f + offset_x, 0.3f + offset);
	rs->DrawQuadList(1, &q, "ui/fire.tga");

	offset_x = sin(sys->Milliseconds() / 5000.0f);
	q.uv0	= EVec2(0.0f + offset_x, 0.0f + 2*offset);
	q.uv1	= EVec2(0.4f + offset_x, 0.4f + 2*offset);
	rs->DrawQuadList(1, &q, "ui/fire.tga");

	offset_x = sin(sys->Milliseconds() / 6000.0f);
	q.uv0	= EVec2(0.0f + offset_x, 0.0f + 3*offset);
	q.uv1	= EVec2(0.9f + offset_x, 0.7f + 3*offset);
	rs->DrawQuadList(1, &q, "ui/fire.tga");

	offset_x = sin(sys->Milliseconds() / 5500.0f);
	q.uv0	= EVec2(0.0f + offset_x, 0.0f + 4*offset);
	q.uv1	= EVec2(1.0f + offset_x, 0.6f + 4*offset);
	rs->DrawQuadList(1, &q, "ui/fire.tga");

	// City on the background :
	rs->DrawStretchImage(0, 0, 1, 1, "ui/background.tga");

	rs->Set2DViewMode();
}











